#include<reg51.h>
#include <intrins.h>

typedef unsigned int uint;
typedef unsigned char uchar;

sbit note = P3^6;

uint i, j, n;

uchar num[] = {0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xd8, 0x80};
uchar demo[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

void delay_ms(uint ms)
{
    uint i, j;
    while(ms--)
    {
        for (i = 0; i < 2; i++)
        {
            for(j = 0; j < 122; j++);
        }
    }
}

void EXINT2() interrupt 2
{
    EX1 = 0;
    delay_ms(20);
    EX1 = 1;
    if (n == 1)
    {
        for(i = 0; i < 10; i++)
        {
            if (P2 == demo[i])
            {
                P0 = num[i];
                delay_ms(20);
                P1 = demo[i];
                delay_ms(30);
                note = 1;
                delay_ms(40);
                n = 0;
                break;
            }
        }
    }
    
}
void EXINT0() interrupt 0
{
    EX0 = 0;
    EX0 = 1;
    delay_ms(20);
    note = 0;
    n = 1;
    P1 = 0xff;
    P0 = 0xff;
}

//TODO:利用定时器实现延时&在host操作之后，流水灯，考虑中断优先级
void main()
{
    EA = 1;
    IP = 0x04;
    EX0 = 1;
    EX1 = 1;
    IT1 = 1;
    P2 = 0xff;
    while (1);
    
}

